<!DOCTYPE html>
<html>
<head>
#include("../../_common/head.html")
<title>任务日志列表</title>
</head>
<body class="pear-container">
    <div class="layui-panel query-panel /*查询面板*/">
        <form class="layui-form layui-row layui-col-space16" lay-filter="query-form" onsubmit="return false;">
        	<div class="layui-col-xl2 layui-col-lg2 layui-col-md2 layui-col-sm3 layui-col-xs6">
				<div class="layui-input-wrap">
					<div class="layui-input-prefix">
						<i class="layui-icon layui-icon-date"></i>
					</div>
					<input id="startTime" type="text" name="startDate" value="#(startDate??)" placeholder="开始日期" autocomplete="off" class="layui-input select-time" value="#(startDate??)">
				</div>
		    </div>
        	<div class="layui-col-xl2 layui-col-lg2 layui-col-md2 layui-col-sm3 layui-col-xs6">
				<div class="layui-input-wrap">
					<div class="layui-input-prefix">
						<i class="layui-icon layui-icon-date"></i>
					</div>
                    <input id="endTime" type="text" name="endDate" value="#(endDate??)" placeholder="结束日期" autocomplete="off" class="layui-input select-time">
				</div>
		    </div>
        	<div class="layui-col-xl2 layui-col-lg2 layui-col-md2 layui-col-sm3 layui-col-xs6">
				<div class="layui-input-wrap">
					<div class="layui-input-prefix">
						<i class="pear-icon pear-icon-text"></i>
					</div>
					<input type="text" name="word" value="#(word??)" placeholder="模糊查询" autocomplete="off" class="layui-input" lay-affix="clear">
				</div>
		    </div>
        	<div class="layui-col-xl2 layui-col-lg2 layui-col-md2 layui-col-sm3 layui-col-xs6">
				<div class="layui-input-wrap">
                    <select name="group">
                        <option value="">-- 任务分组 --</option>
                        #DICTS(type="job_group")#for(item : dicts)
                        <option value="#(item.value)"#if(group?? == item.value) selected#end>#(item.label)</option>
                        #end#end
                    </select>
				</div>
		    </div>
        	<div class="layui-col-xl2 layui-col-lg2 layui-col-md2 layui-col-sm3 layui-col-xs6">
				<div class="layui-input-wrap">
                    <select name="status">
                        <option value="">-- 执行状态 --</option>
                        #DICTS(type="job_execution_status")#for(item : dicts)
                        <option value="#(item.value)"#if(status?? == item.value) selected#end>#(item.label)</option>
                        #end#end
                    </select>
				</div>
		    </div>
            <div class="layui-col-xl2 layui-col-lg2 layui-col-md2 layui-col-sm3 layui-col-xs6">
                <button type="button" class="pear-btn pear-btn-sm pear-btn-primary query-form-search">
                    <i class="layui-icon layui-icon-search"></i> 搜索
                </button>
                <button type="button" class="pear-btn pear-btn-sm query-form-reset">
                    <i class="layui-icon layui-icon-refresh"></i> 重置
                </button>
            </div>
        </form>
    </div>
    <div class="layui-panel data-panel /*数据面板*/">
        <table id="data-table" lay-filter="data-table"></table>
    </div>

<!-- 状态分组 -->
<script type="text/html" id="bean-jobGroup">
<!-- #DICTS(type="job_group")#for(item : dicts) -->
#[[{{# if(d.group == ']]##(item.value)#[[') { }}]]#
    <span class="#(item.listClass)">#(item.label)</span>
#[[{{# } }}]]#
<!-- #end#end -->
</script>

<!-- 执行状态字段 -->
<script type="text/html" id="bean-jobExecutionStatus">
<!-- #DICTS(type="job_execution_status")#for(item : dicts) -->
#[[{{# if(d.status == ']]##(item.value)#[[') { }}]]#
    <span class="#(item.listClass)">#(item.label)</span>
#[[{{# } }}]]#
<!-- #end#end -->
</script>

<!-- 调度时间 -->
<script type="text/html" id="bean-startedDatetime">
    {{layui.util.toDateString(d.startedDatetime, "yyyy-MM-dd HH:mm:ss")}}
</script>
    
#authPermissions('monitor:jobLog:clear')
    #set(tableButtonsHtml = '<a class="pear-btn pear-btn-danger pear-btn-xs" round lay-event="clear"><i class="layui-icon layui-icon-close"></i>&nbsp;清空</a>') ### 自定义表头按钮
#end
#authPermissions('monitor:job:detail', 'monitor:job:detail')
    #set(recordButtonsHtml = '') ### 自定义单记录按钮
#end
#include("../../_common/data_table_template.html"
    , customTableButtons = tableButtonsHtml
    , customRecordButtons = recordButtonsHtml
)

#include("../../_common/foot.html")

<script type="text/javascript">
/*
 * 定义权限开关
 */
var RIGHTS = { NONAME: null // 无用，占个位
//#authPermissions('monitor:job:del')
    ,remove: true
    ,batchRemove: true
//#end
//#authPermissions('monitor:job:detail')
    ,detail: true
//#end

};

/*
 * 模块操作路径
 */
var MODULE_PATH = "#CTX()/admin/monitor/jobLog/";

/*
 * 默认弹窗大小
 */
var POPUP_AREA = ['720px', '95%'];

/*
 * 数据表的OPTIONS
 */
var OPTIONS = {
    elem: '#data-table',
    url: MODULE_PATH + "query",
    method: "post",
    request: {pageName: 'pageNumber', limitName: 'pageSize' },
    initSort: {"field": "startedDatetime", "type": "desc"},
    page: true,
    height: 'full-95',
    toolbar: '#table-toolbar',
    defaultToolbar: [{title: "查询", layEvent: "toggle", icon: "layui-icon-search"}, 'filter'],
    size: 'sm',
    cols: [[
        {type: 'checkbox', align: 'center', width: 60},
        {field: 'name', align: 'left', minWidth: 150, width: '10%', sort: true, title: '任务名称'},
        {field: 'group', align: 'left', minWidth: 80, width: '10%', sort: true, title: '任务分组', templet: '#bean-jobGroup'},
        {field: 'target', align: 'left', minWidth: 150, width: '15%', title: '调用目标字符串'},
        {field: 'message', align: 'left', minWidth: 200, width: '20%', title: '日志信息'},
        {field: 'status', align: 'center', width: 100, sort: true, title: '执行状态', templet: '#bean-jobStatus'},
        {field: 'cost', align: 'center', minWidth: 100, width: '8%', sort: true, title: '耗时(ms)'},
        {field: 'startedDatetime', align: 'center', width: 160, sort: true, title: '调度时间', templet: '#bean-startedDatetime'},
        {toolbar: '#record-toolbar', align: 'left', minWidth: 240, title: '操作'}
    ]]
};
</script>

<script src="#CTX()/admin/js/query_form.js?_v=#VERSION()"></script>
<script src="#CTX()/admin/js/data_table.js?_v=#VERSION()"></script>

<script type="text/javascript">
/*
 * Layui相关脚本
 */
layui.use(['jquery', 'common', 'form', 'dropdown'], () => {
    var $ = layui.jquery, form = layui.form, common = layui.common;
    var datatable = layui.table; // 数据表格
    
    /*
     * 清空操作
     */
    window.clear = function() {
        layer.confirm("确认清空所有记录吗？", {
            icon: 3,
            title: '确认'
        }, function(index) {
            layer.close(index);
            $.ajax({
                url: MODULE_PATH + "clear",
                method: "post",
                data: form.val("query-form"),
                beforeSend : function(){layer.load();}, // 防止重复操作
                complete : function(){layer.closeAll('loading');}, //解除防重复操作
                success: function(result) {
                    if (result.code == 200) {
                        layer.alert("操作成功！", {icon: 1});
                        window.dataTable.search();
                    } else {
                        if(result.description){
                            // Ajax调用成功，但后台返回失败信息
                            layer.alert(result.description, {icon: 5});
                        } else {
                            layer.alert("操作失败！", {icon: 2});
                        }
                    }
                }
            });
        });
    }

    /*
     * 监听自定义事件
     */
    window.dataTable.handleEvent = (event, obj) => {
        if (event === 'clear') {
        	window.clear();
        }
    }
    
    /*
     * 页面加载完成时加载表格数据
     */
    $(document).ready(() => {
        window.dataTable.search();
    });
    
});
</script>
</body>
</html>
